package com.qumitech.visualnovel.service.retain.impl;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.datasource.console.RetainConfigMapper;
import com.qumitech.visualnovel.pubdef.dto.retain.RetainMessageDTO;
import com.qumitech.visualnovel.service.retain.RetainMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class RetainMessageServiceImpl implements RetainMessageService {

    @Autowired
    RetainConfigMapper retainConfigMapper;

    @Override
    public List<HashMap<String, Object>> listRetainMessages(Integer type, String title, String content, String orderBy, String orderType, int offset, int limit) {
        return retainConfigMapper.listRetainMessages(type, title, content, orderBy, orderType, offset, limit);
    }

    @Override
    public int countRetainMessages(Integer type, String title, String content) {
        return retainConfigMapper.countRetainMessages(type, title, content);
    }

    @Override
    public void updateRetainMessages(RetainMessageDTO retainMessageDTO) {
        Long id = retainMessageDTO.getId();
        if (id == null) {
            retainConfigMapper.createRetainMessage(retainMessageDTO);
        } else {
            retainConfigMapper.updateRetainMessage(retainMessageDTO);
        }
    }

    @Override
    public void deleteRetainMessage(Integer id) {
        retainConfigMapper.deleteRetainMessage(id);
    }

}
